<?php
namespace app\admin\controller;
use think\Config;
use think\Db;
use think\Request;


class Order extends Base{

    public $shopId;
    public $ownerUid;

    public $order_status;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);

        $shop = getUserShop('system');
        if(!$shop){
            $this->redirect('product/shop');
        }

        $this->ownerUid = 0;
        $this->shopId = $shop->id;
        $this->order_status = Config::get('order_status');
        $this->assign('order_status', $this->order_status);

    }

    public function order($k='',$t=''){

        if($t=='waitSend'){
            $orders = model('order')->getOwnerOrders($this->ownerUid,$this->shopId,'jiujiu_order.status=1');
        }
        elseif($t=='waitRefund'){
            $orders = model('order')->getOwnerOrders($this->ownerUid,$this->shopId,"jiujiu_order.status2>0 and jiujiu_order.status2<7");
        }
        elseif($t=='successRefund'){
            $orders = model('order')->getOwnerOrders($this->ownerUid,$this->shopId,'jiujiu_order.status=8');
        }
        else{
            $orders = model('order')->getOwnerOrders($this->ownerUid,$this->shopId,'jiujiu_order.status>0');
        }
        $this->assign('isPagination',1);
        $this->assign('orders',$orders);
        $this->assign('k',$k);
        $this->assign('t',$t);
        return view('order');

    }




    public function order_search(){
        $t = Request::instance()->get('t');
        $k = Request::instance()->get('k');

        if($t=='waitSend'){
            $orders = model('order')->getOwnerOrdersBySearch($this->ownerUid,$this->shopId,'jiujiu_order.status=1',$k);
        }
        elseif($t=='waitRefund'){
            $orders = model('order')->getOwnerOrdersBySearch($this->ownerUid,$this->shopId,'jiujiu_order.status2>0 and jiujiu_order.status2<7',$k);
        }
        elseif($t=='successRefund'){
            $orders = model('order')->getOwnerOrdersBySearch($this->ownerUid,$this->shopId,'jiujiu_order.status=8',$k);
        }
        else{
            $orders = model('order')->getOwnerOrdersBySearch($this->ownerUid,$this->shopId,'jiujiu_order.status>0',$k);
        }
        $this->assign('orders',$orders);
        $this->assign('k',$k);
        $this->assign('t',$t);
        return view('order');

    }


    public function order_detail($id){

        if(!$id){
            $id = Request::instance()->get('id');
        }
       $order = model('order')->getInfoById($id);
       $refund = model('refund')->where('orderId',$id)->find();
       $this->assign('order',$order);
       $this->assign('refund',$refund);
       $this->assign('expressCompany',Config::get('express'));
        return view('order_detail');
    }


    public function sendOrder(){
        $data = Request::instance()->post();
        model('order')->sendOrder($data['id'],$data['expressCompany'],$data['expressNum']);
        $this->redirect('order_detail',['id'=>$data['id']]);
    }




    public function changeRefund($id,$rs){

        changeRefund($id,$rs);
        $this->redirect('order_detail',['id'=>$id]);
    }








}